# Change the syntax highlighting to Ruby
# All lines starting with a # are ignored when running fastlane

# If you want to automatically update fastlane if a new version is available:
# update_fastlane

# This is the minimum version number required.
# Update this, if you use features of a newer version
fastlane_version "2.29.0"

default_platform :ios
skip_docs

platform :ios do
  before_all do
  end

  lane :install do
    bundle_install
    cocoapods(
      use_bundle_exec: true,
      try_repo_update_on_error: true
    )

    #carthage(
    #  command: "bootstrap",
    #  use_ssh: true,   
    #  platform: "iOS", 
    #)
  end

  lane :build do
    install

    #Dir.chdir("..") do
      swiftlint(
        mode: :lint, 
        config_file: ".swiftlint.yml",
        executable: "Pods/SwiftLint/swiftlint",
        ignore_exit_status: true
      )
    #end

    xcodebuild(
      project: "FlexLayout.xcodeproj",
      scheme: "FlexLayout",
      configuration: "Release",
      build: true,
      clean: true,
      destination: "platform=iOS Simulator,name=iPhone X,OS=12.2"
    )

    #xcodebuild(
    #  workspace: "FlexLayout.xcworkspace",
    #  scheme: "FlexLayoutTVOS",
    #  configuration: "Release",
    #  build: true,
    #  clean: true
    #  destination: "platform=iOS Simulator,name=iPhone X,OS=12.2"
    #)

    xcodebuild(
      workspace: "FlexLayout.xcworkspace",
      scheme: "FlexLayoutSample",
      configuration: "Release",
      build: true,
      clean: true,
      destination: "platform=iOS Simulator,name=iPhone X,OS=12.2"
    )
  end

  lane :tests do
    # sh "buck test :yoga "
    scan(scheme: "FlexLayoutSample", 
         workspace: "FlexLayout.xcworkspace")
  end

  lane :doc do 
    jazzy
  end

  lane :travis do
    build
    tests
    #pod_lib_lint(allow_warnings: true, verbose: false)
  end

  lane :deploy do
    ensure_git_branch
    version = version_bump_podspec(path: "FlexLayout.podspec")
    git_commit(path: ["./FlexLayout.podspec"], message: "Bumped to version #{version}")
    push_to_git_remote(remote_branch: 'master', force: false, tags: true)
    changelog = changelog_from_git_commits
    github_release = set_github_release(
      repository_name: "layoutBox/FlexLayout",
      api_token: ENV['GITHUB_TOKEN'],
      name: version,
      tag_name: version,
      description: changelog,
      commitish: "master"
    )
    sh("git fetch --tags")
    pod_push(allow_warnings: true, verbose: true)
  end

end
